//暗黑游戏 二维的混合背包
#include <iostream>
using namespace std;
const int MAXN=150;
const int MAXP=100;
const int MAXR=100;
int n,p,r;
int pg[MAXN+1],rune[MAXN+1],num[MAXN+1],power[MAXN+1];
int maxpower[MAXP+1][MAXR+1];

int main(){
    cin>>n>>p>>r;
    for(int i=1;i<=n;i++) cin>>pg[i]>>rune[i]>>num[i]>>power[i];

    for(int i=1;i<=n;i++){
        if (num[i]==0) num[i]=min(p/pg[i],r/rune[i]);
        for(int p1=p;p1>=pg[i];p1--)
            for(int r1=r;r1>=rune[i];r1--)
                for(int k=1;k<=num[i];k++)
                    if (p1>=k*pg[i]&&r1>=k*rune[i]&&(maxpower[p1][r1]<maxpower[p1-k*pg[i]][r1-k*rune[i]]+k*power[i]))
                        maxpower[p1][r1]=maxpower[p1-k*pg[i]][r1-k*rune[i]]+k*power[i];
    }
    cout<<maxpower[p][r];
}